/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Models.Company;
import Models.Drivers;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author phuong
 */

public class RequestDAO {
    
    static ResultSet rs = null;
    static Connection con=null;
    static java.sql.Statement stm = null;
    public static List<Drivers> requestFromDriver() throws Exception{
        List lst = new ArrayList();
        con = (Connection) DBConnection.myConnection();
        stm = con.createStatement();
        rs = stm.executeQuery("Select * from Driver where Status is null");        
        while(rs.next()){
            Drivers dr = new Drivers(rs.getInt("ID"), rs.getString("Name"), rs.getString("ContactPerson"), rs.getString("Address"), rs.getString("City"), rs.getString("Mobile"), rs.getString("Telephone"), rs.getString("Experience"), rs.getString("Description"), rs.getBoolean("Status"));
            lst.add(dr);            
        }
        con.close();        
        return lst;
    }
    public static List<Company> requestFromList() throws Exception{
        List listing = new ArrayList();
        con = (Connection) DBConnection.myConnection();
        stm = con.createStatement();
        rs = stm.executeQuery("Select * from Company where Status is null");        
        while(rs.next()){
            Company lt= new Company(rs.getInt("ID"), rs.getString("Name"), rs.getString("ContactPerson"), rs.getString("Designation"), rs.getString("Address"), rs.getString("Mobile"), rs.getString("Telephone"), rs.getString("Fax"), rs.getString("MemberType"), rs.getBoolean("Status"));
            listing.add(lt);            
        }
        con.close();        
        return listing;
    }
    public static void updateAcceptDriver(int id) throws Exception{        
        String sta = "true";
        con  = (Connection)DBConnection.myConnection();
        String sql = "update Driver set [Status]=? where ID=?";
        PreparedStatement st = con.prepareStatement(sql);
        st.setString(1, sta);
        st.setInt(2, id);        
        st.executeUpdate();        
    }
    public static void updateDenyDriver(int id) throws Exception{
        String sta = "false";
        con  = (Connection)DBConnection.myConnection();
        String sql = "update Driver set [Status]=? where ID=?";
        PreparedStatement st = con.prepareStatement(sql);
        st.setString(1, sta);
        st.setInt(2, id);
        st.executeUpdate();
    }
    public static void updateAcceptList(int id) throws Exception{        
        String sta = "true";
        con  = (Connection)DBConnection.myConnection();
        String sql = "update Company set [Status]=? where ID=?";
        PreparedStatement st = con.prepareStatement(sql);
        st.setString(1, sta);
        st.setInt(2, id);        
        st.executeUpdate();        
    }
    public static void updateDenyList(int id) throws Exception{
        String sta = "false";
        con  = (Connection)DBConnection.myConnection();
        String sql = "update Company set [Status]=? where ID=?";
        PreparedStatement st = con.prepareStatement(sql);
        st.setString(1, sta);
        st.setInt(2, id);
        st.executeUpdate();
    }

}
